package com.books.controller.order;

import com.books.model.bo.Result;
import com.books.model.entity.order.BuyOrder;
import com.books.model.entity.order.OrderList;
import com.books.service.order.IBuyOrderServer;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZhouRui
 * @title: 码上就来
 * @projectName cbstore-spring-boot
 * @description: TODO
 * @date 2021/10/1616:04
 */

@RestController
@RequestMapping(value = "/confirm",method = RequestMethod.GET)
public class OrderListController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/del")
    @ResponseBody
    public Result delorder(String bid) {
        redisTemplate.delete("ocode"+bid);
        redisTemplate.delete("bcode"+bid);
        return new Result("500","删除成功");
    }

    @GetMapping("/show")
    @ResponseBody
    public Result showorder(String bid){
        List<OrderList> orderLists;
        orderLists= (List<OrderList>) redisTemplate.opsForValue().get("bcode"+bid);
        System.out.println(orderLists);
        return new Result("200","展示如下",orderLists);
    }

    @PostMapping
    @ResponseBody
    public Result repay(String bid){
        BuyOrder buyOrder;
        List<OrderList> orderLists;
        buyOrder= (BuyOrder) redisTemplate.opsForValue().get("ocode"+bid);
        return new Result("200","支付成功",buyOrder);
    }
}